#include "nameconvertertest.h"
#include <QDebug>
#include <common/logger/logger.h>
NameConverterTest::NameConverterTest(QObject* parent)
	: QObject(parent)
{
}
NameConverterTest::~NameConverterTest()
{
}
void NameConverterTest::initTestCase()
{
	qDebug() << "NameConverterTest::initTestCase";
}
void NameConverterTest::tstName2NameInfoSingle()
{

	//两字姓名
	QString testName1 = "张三";
	NameInfo result1 = NameConverter::cvt2NameInfo(testName1);
	QVERIFY(!result1.surName.isEmpty());
	QVERIFY(!result1.personalName.isEmpty());

	QCOMPARE(result1.surName, QString("张"));
	QCOMPARE(result1.personalName, QString("三"));
	QCOMPARE(result1.surnameSpl, QString("zhang"));
	QCOMPARE(result1.personalNameSpl, QString("san"));
	QCOMPARE(result1.surNameFspl, QString("z"));
	QCOMPARE(result1.personalNameFspl, QString("s"));

	//三字姓名
	QString testName2 = "王老五";
	NameInfo result2 = NameConverter::cvt2NameInfo(testName2);
	QVERIFY(!result2.surName.isEmpty());
	QVERIFY(!result2.personalName.isEmpty());

	QCOMPARE(result2.surName, QString("王"));
	QCOMPARE(result2.personalName, QString("老五"));
	QCOMPARE(result2.surnameSpl, QString("wang"));
	QCOMPARE(result2.personalNameSpl, QString("lao wu"));
	QCOMPARE(result2.surNameFspl, QString("w"));
	QCOMPARE(result2.personalNameFspl, QString("lw"));
	qDebug() << "单字姓氏姓名通过";
}
void NameConverterTest::tstName2NameInfoMulti()
{
	//复姓3字
	QString testName1 = "欧阳修";
	NameInfo result1 = NameConverter::cvt2NameInfo(testName1);

	QVERIFY(!result1.surName.isEmpty());
	QVERIFY(!result1.personalName.isEmpty());
	QCOMPARE(result1.surName, QString("欧阳"));
	QCOMPARE(result1.personalName, QString("修"));
	QCOMPARE(result1.surnameSpl, QString("ou yang"));
	QCOMPARE(result1.personalNameSpl, QString("xiu"));
	QCOMPARE(result1.surNameFspl, QString("oy"));
	QCOMPARE(result1.personalNameFspl, QString("x"));

	//复姓4字
	QString testName2 = "司马相如";
	NameInfo result2 = NameConverter::cvt2NameInfo(testName2);
	QVERIFY(!result2.surName.isEmpty());
	QVERIFY(!result2.personalName.isEmpty());

	QCOMPARE(result2.surName, QString("司马"));
	QCOMPARE(result2.personalName, QString("相如"));
	QCOMPARE(result2.surnameSpl, QString("si ma"));
	QCOMPARE(result2.personalNameSpl, QString("xiang ru"));
	QCOMPARE(result2.surNameFspl, QString("sm"));
	QCOMPARE(result2.personalNameFspl, QString("xr"));
	qDebug() << "复姓通过";
}

void NameConverterTest::tstNameLenght()
{
	//一个字不符合命名规则
	QString name1 = "张";
	NameInfo result1 = NameConverter::cvt2NameInfo(name1);
	QVERIFY(result1.surName.isEmpty());

	//暂时没限制长度要求
	// QString name2="哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈";
	// NameInfo result2 = NameConverter::cvt2NameInfo(name2);
	// QVERIFY(result2.surName.isEmpty());
	// qDebug()<<"姓名长度通过";
}

void NameConverterTest::tstNameSpecialChar()
{
	QString name = "张三-";
	NameInfo result = NameConverter::cvt2NameInfo(name);
	QVERIFY(result.surName.isEmpty());

	QString name2 = "李四n";
	NameInfo result2 = NameConverter::cvt2NameInfo(name2);
	QVERIFY(result2.surName.isEmpty());
	qDebug() << "姓名特殊字符通过";
}

void NameConverterTest::tstEnthnicityChar()
{
	QString hanName = "李明浩";
	NameInfo hanResult = NameConverter::cvt2NameInfo(hanName, Ethnicity::HAN);
	QCOMPARE(hanResult.surName, QString("李"));
	QCOMPARE(hanResult.personalName, QString("明浩"));
	QCOMPARE(hanResult.surnameSpl, QString("li"));
	QCOMPARE(hanResult.personalNameSpl, QString("ming hao"));
	QCOMPARE(hanResult.surNameFspl, QString("l"));
	QCOMPARE(hanResult.personalNameFspl, QString("mh"));
	qDebug() << "汉族命名规则测试通过";
	QString uyghurName = "阿里·阿不都热合曼·买买提";
	NameInfo uyghurResult = NameConverter::cvt2NameInfo(uyghurName, Ethnicity::UYGHUR);
	QCOMPARE(uyghurResult.surName, QString("阿不都热合曼·买买提"));
	QCOMPARE(uyghurResult.personalName, QString("阿里"));
	QCOMPARE(uyghurResult.surnameSpl, QString("a bu dou re he man · mai mai ti"));
	QCOMPARE(uyghurResult.personalNameSpl, QString("a li"));
	QCOMPARE(uyghurResult.surNameFspl, QString("abdrhm·mmt"));
	QCOMPARE(uyghurResult.personalNameFspl, QString("al"));
	qDebug() << "维吾尔族命名规则测试通过";
	QString tibetanName = "扎西多吉";
	NameInfo tibetanResult = NameConverter::cvt2NameInfo(tibetanName, Ethnicity::TIBETAN);
	QVERIFY(tibetanResult.surName.isEmpty());
	QCOMPARE(tibetanResult.personalName, QString("扎西多吉"));
	QVERIFY(tibetanResult.surnameSpl.isEmpty());
	QCOMPARE(tibetanResult.personalNameSpl, QString("zha xi duo ji"));
	QVERIFY(tibetanResult.surNameFspl.isEmpty());
	QCOMPARE(tibetanResult.personalNameFspl, QString("zxdj"));
	qDebug() << "藏族命名规则测试通过";
	// 测试4: 俄罗斯族命名规则（名·父名·姓）
	QString russianName = "伊万·伊万诺维奇·伊万诺夫";
	NameInfo russianResult = NameConverter::cvt2NameInfo(russianName, Ethnicity::RUSSIAN);
	QCOMPARE(russianResult.surName, QString("伊万诺夫"));
	QCOMPARE(russianResult.personalName, QString("伊万"));
	QCOMPARE(russianResult.surnameSpl, QString("yi wan nuo fu"));
	QCOMPARE(russianResult.personalNameSpl, QString("yi wan"));
	QCOMPARE(russianResult.surNameFspl, QString("ywnf"));
	QCOMPARE(russianResult.personalNameFspl, QString("yw"));
	qDebug() << "俄罗斯族命名规则测试通过";
	// 测试5: 蒙古族可能的带点命名规则（姓·名）
	QString mongolName = "儿只斤·铁木真";
	NameInfo mongolResult = NameConverter::cvt2NameInfo(mongolName, Ethnicity::MONGOL);
	QCOMPARE(mongolResult.surName, QString("儿只斤"));
	QCOMPARE(mongolResult.personalName, QString("铁木真"));
	QCOMPARE(mongolResult.surnameSpl, QString("er zhi jin"));
	QCOMPARE(mongolResult.personalNameSpl, QString("tie mu zhen"));
	QCOMPARE(mongolResult.surNameFspl, QString("ezj"));
	QCOMPARE(mongolResult.personalNameFspl, QString("tmz"));
	qDebug() << "蒙古族带点命名规则测试通过";
	QString derungName = "孔当·迪";
	NameInfo derungResult = NameConverter::cvt2NameInfo(derungName, Ethnicity::DERUNG);
	QCOMPARE(derungResult.surName, QString("孔当"));
	QCOMPARE(derungResult.personalName, QString("迪"));
	QCOMPARE(derungResult.surnameSpl, QString("kong dang"));
	QCOMPARE(derungResult.personalNameSpl, QString("di"));
	QCOMPARE(derungResult.surNameFspl, QString("kd"));
	QCOMPARE(derungResult.personalNameFspl, QString("d"));
	qDebug() << "独龙族命名规则测试通过";
}


void NameConverterTest::cleanUpTestCase()
{
	qDebug() << "CLASS:NameConverterTest END";
}
int main(int argc, char** argv)
{
	NameConverterTest tc;
	return QTest::qExec(&tc, argc, argv);// qExec 会把失败信息打印到 stdout
}
